//
//  HeaderViewController.m
//  reacticons
//
//  Created by Admin on 7/4/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "HeaderViewController.h"
#import "AppDelegate.h"
#import "ImageListViewController.h"
@implementation HeaderViewController
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"header view");
        NSMutableArray *recentlyAddedArray=[[NSMutableArray alloc] init];
        recentlyAddedArray=[[(AppDelegate*)[[UIApplication sharedApplication] delegate] dataManager] readRecentlyItemsWithType:@"recentlyAdded"];
        NSLog(@"header view 1");

        if (recentlyAddedArray) {
            if (recentlyAddedArray.count>0) {
                recentlyAdded=[[recentlyAddedArray objectAtIndex:0] retain];
            }
        }
        
        
        NSMutableArray *recentlyUsedArray=[[NSMutableArray alloc] init];

        recentlyUsedArray=[[(AppDelegate*)[[UIApplication sharedApplication] delegate] dataManager] readRecentlyItemsWithType:@"recentlyUsed"];
        
        if (recentlyUsedArray) {
            if (recentlyUsedArray.count>0) {
                recentlyUsed=[[recentlyUsedArray objectAtIndex:0] retain];
            }    
        }
        NSLog(@"pass");
        if (recentlyAdded) {
            recentlyAddedView =[[EGOImageView alloc] initWithFrame:CGRectMake(0, 0, 158, 120)];
            [recentlyAddedView setImageURL:[NSURL URLWithString:recentlyAdded.field3]];
            [recentlyAddedView setContentMode:UIViewContentModeScaleToFill];
        }
        if (recentlyUsed) {
            recentlyUsedView =[[EGOImageView alloc] initWithFrame:CGRectMake(162, 0, 158, 120)];
            [recentlyUsedView setImageURL:[NSURL URLWithString:recentlyAdded.field3]];
            [recentlyUsedView setContentMode:UIViewContentModeScaleToFill];
        }
        [self.view insertSubview:recentlyAddedView atIndex:0];
        [self.view insertSubview:recentlyUsedView atIndex:0];
        // sCustom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Buttons On Clicked

- (IBAction)buttonsOnClicked:(id)sender
{
//    [self.delegate clickedHeaderBtn:sender];
    

    switch ([sender tag]) {
        case 0:
            //  Call the view of all images
            NSLog(@"Folder of all images");
            NSLog(@"%@||%@",recentlyAdded.image,recentlyAdded.field4);
            ImageListViewController * rootView = [[ImageListViewController alloc] init];
            [rootView setParentID:@"recentlyAdded"];
            [rootView setTitle:@"Recently Added"];
            [super.navigationController pushViewController:rootView animated:YES];
            [rootView release];
            break;
            
        case 1:
            //  Call the view of recent used images
            NSLog(@"Folder of recent used images");
            NSLog(@"%@||%@",recentlyUsed.image,recentlyUsed.field5);
            ImageListViewController * rootView2 = [[ImageListViewController alloc] init];
            [rootView2 setParentID:@"recentlyUsed"];
            [rootView2 setTitle:@"Recently Used"];
            [super.navigationController pushViewController:rootView2 animated:YES];
            [rootView2 release];
            break;
            
        default:
            break;
    }
}
- (void)clickedHeaderBtn:(id)sender{
    
}


@end
